package com.stream.jikethirdtask.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xiaoqiang
 * @Description:
 * @Date: 2022/12/11
 * @Version: 1.0
 */
@RestController
public class SendMsgController {

    @Autowired
    private Source source;

    /**
     * 发送消息
     * @param msg
     * @return
     */
    @GetMapping("sendMsg")
    public Object sendMsg(String msg){
        MessageBuilder<String> stringMessageBuilder = MessageBuilder.withPayload(msg);
        source.output().send(stringMessageBuilder.build());
        return "message sended "+msg;
    }
}
